﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="room.aspx.cs" Inherits="EZCRS.HCMS.Web.manage.AIR.room" %>

<%@ Register Src="../usercontrol/titlepage.ascx" TagName="titlepage" TagPrefix="uc2" %>
<%@ Register Assembly="Book38.Net.CustomControl" Namespace="Book38.Net.CustomControl"
    TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link type="text/css" href="../../style/main.css" rel="Stylesheet" />
    <style>
        .planlist
        {
            margin-top: 5px;
            overflow-x: hidden;
            overflow-y: auto;
            width: 400px;
            height: 250px;
            border: solid 1px #D9ECFF;
        }   
             
        #labcol
        {
        	color:Red;
        	font-weight:bold;
        }
        
    </style>

    <script src="../../common/calendar1.js" language="javascript" type="text/javascript"></script>

    <script src="../../Common/jquery-1.2.6.min.js"></script>

    <script>
    
        var sending = false;
        var hasColl = -1;
        var lasttick = 0;
        
        $(document).ready(function() {
        
             $('form').submit(function(){
            
               if(hasColl == 1){
               
                    return confirm("部分计划与之前设置的时间段有冲突，是否继续？");
               }
               else if(hasColl == -1 && sending){
               
                    return confirm("正在验证计划时间段是否冲突，是否现在就提交？");

               }
               
               return true;
            });
            
            $("#btnsave").click(function() {
            
                //验证
                var regxDay = /^\d+$/;
                var regxNum = /^-?\d+$/;
                var regxRate = /^-?\d+(\.\d+)?$/;
                
                if(!checkValue('txtMin', regxDay, false)) {
                    alert('请填写正确的最小入住天数！');
                    return false;
                }
                
                if(!checkValue('txtMax', regxDay, false)) {
                    alert('请填写正确的最大入住天数！');
                    return false;
                }
                
                if(!checkValue('txtInventory', regxNum, true)) {
                    alert('请填写正确的房量！');
                    return false;
                }
                
                return true;
                
            });
            
            
            $("#cblRoom input").click(function(){
                
                IsCollision();
            
            });

            $('#GridView1 input').blur(function(){
            
                IsCollision();
                
            });
            
            $("#startdate").blur(function (){
            
                IsCollision();
            
            });
            
            $("#enddate").blur(function (){
            
                IsCollision();
            
            });
        });
        
        
        //检查是否存在冲突...
        function IsCollision(){
        
            if(sending) return;
            
            hasColl = -1;
            
            var strPlanCodeList = "";
            var strRoomCodeList = "";
            
            $("#cblRoom input").each(function(i){
                
                if($(this).attr("checked")){
                
                    var id = $(this).attr("id");
                    
                    var s = "#cblRoom" + " label";

                    $(s).each(function(){
                        
                        if($(this).attr("for") == id)
                            
                            var name = $(this).text();
                            
                            $('#cblRoom span').each(function(){
                            
                                if($(this).attr("n") == name)
                                    strRoomCodeList += $(this).attr("v") + ",";
                                    
                            });
                            
                        
                    });
                }
            
            });
            
            if(strRoomCodeList != ""){
            
                $("#GridView1 input").each(function(i){
                    
                    //alert($(this).val());
                    
                    if($(this).val() != ""){
                        
                        var id = $(this).attr("id");
                        
                        var rgx = /txtQuota$/;
                        
                        var s = id.replace(rgx, "lblCode");
                        
                        strPlanCodeList += $('#' + s).html() + ",";
                    
                    }
                
                });
            }
            
            var startdate = "";
            var enddate = "";
            var sid = "";
            
            var bpass = false;
            
            if(strPlanCodeList != "" && strRoomCodeList != ""){
            
                //get date
                startdate = $("#startdate").val();
                enddate = $("#enddate").val();
                
                if(startdate != "yyyy-MM-dd" && enddate != "yyyy-MM-dd"){
                
                    //pass
                    bpass = true;
                }
            }
            
            if(bpass && !sending){
                
                var data = {
                
                    startdate:startdate,
                    enddate:enddate,
                    plans:strPlanCodeList,
                    roomcode:strRoomCodeList
                };
                
                $.post("plan.aspx?act=coll", data,
                
                    function(data, state){
                    
                         doCallback(data);
                                
                    }, "json");
               
               sending = true;
               
               $('#labcol').text("正在检查冲突...");
               
            }
            
        }
        
        function doCallback(r){
        
            if(r.coll != ""){
            
                $('#labcol').text("计划代码：" + r.coll + "与之前设置的时间段有冲突。");
                hasColl = 1;
            }
            else{
                $('#labcol').text("");
                
                hasColl = 0;
            }
            
            sending = false;
        
        }
        
        function checkValue(obj, regx, need) {

            var elem = document.getElementById(obj);
            
            if(elem.value == '' && need) {
                elem.focus();
                return false;
            }
            
            if(elem.value != ''){    
                if (!regx.exec(elem.value)) {
                    elem.focus();
                    return false;
                }
            }
            
            return true;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <uc2:titlepage ID="Titlepage1" runat="server" inittitle="<%$ Resources:Site, TitleExpression %>">
    </uc2:titlepage>
    <table cellpadding="0" cellspacing="0" class="main-table">
        <tr>
            <td>
                <!--#include file="nav.htm"-->
            </td>
        </tr>
        <tr class="line-even">
            <td>
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="50%" valign="top">
                            <table align="center" border="0" cellspacing="0" cellpadding="0" class="maininfo">
                                <tr>
                                    <td colspan="2" class="minfo-title">
                                        房型级：
                                    </td>
                                </tr>
                                <tr>
                                    <td width="80">
                                        房型代码表：
                                    </td>
                                    <td>
                                        <asp:CheckBoxList ID="cblRoom" runat="server" RepeatDirection="Horizontal">
                                        </asp:CheckBoxList>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="80">
                                        时间段：
                                    </td>
                                    <td>
                                        <input id="startdate" type="text" runat="server" class="text-line" value="yyyy-MM-dd" />
                                        &nbsp;
                                        <input id="enddate" type="text" runat="server" class="text-line" value="yyyy-MM-dd" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        星期设置：
                                    </td>
                                    <td>
                                        <asp:CheckBoxList ID="cblWeek" runat="server" RepeatDirection="Horizontal">
                                        </asp:CheckBoxList>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        可用性：
                                    </td>
                                    <td>
                                        <table width="100%">
                                            <tr>
                                                <td width=180>
                                                    状态：</td>
                                                <td>
                                                    <asp:DropDownList ID="ddlStatus" runat="server">
                                                    </asp:DropDownList>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    最少入住天数：</td>
                                                <td>
                                                    <cc1:WebTextBox ID="txtMin" runat="server" CssClass="text-line" Width="50px"
                                                        ValidType="Int"><Value>
</Value></cc1:WebTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    最多入住天数：</td>
                                                <td>
                                                    <cc1:WebTextBox ID="txtMax" runat="server" CssClass="text-line" Width="50px"
                                                        ValidType="Int"><Value>
</Value></cc1:WebTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    提前预订期(小时) ：</td>
                                                <td>
                                                    <cc1:WebTextBox ID="txtAdv" runat="server" CssClass="text-line" Width="50px"
                                                        ValidType="Int"><Value>
</Value></cc1:WebTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    &nbsp;配额：</td>
                                                <td>
                                                    <cc1:WebTextBox ID="txtInventory" runat="server" CssClass="text-line" Width="50px"
                                                        ValidType="Int"><Value>
</Value></cc1:WebTextBox>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;</td>
                                    <td>
                                        <div class="planlist">
                                            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                                                Width="100%" DataKeyNames="rate" onrowdatabound="GridView1_RowDataBound">
                                                <Columns>
                                                    <asp:TemplateField HeaderText="计划代码">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblCode" runat="server" Text=""></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="分配额度(%)">
                                                        <ItemTemplate>
                                                            <asp:TextBox ID="txtQuota" runat="server" CssClass="text-line" MaxLength="3" Width="50px"></asp:TextBox>
                                                        </ItemTemplate>
                                                        <ItemStyle Width="100px" />
                                                    </asp:TemplateField>
                                                </Columns>
                                            </asp:GridView>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;</td>
                                    <td>
                                        <label id="labcol"></label></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" valign="middle">
                            <asp:Button ID="btnsave" runat="server" CssClass="bttn" Text="保存" OnClick="btnsave_Click" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

<script>

//initprovince();	
$F("navs2").className="title1";
</script>

